<script type="text/javascript" src="../static/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="../static/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="../static/ueditor/lang/zh-cn/zh-cn.js"></script>
<link type="text/css" href="../static/ueditor/themes/default/css/ueditor.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="../static/Huploadify-master/Huploadify.css">
<script type="text/javascript" src="../static/Huploadify-master/jquery.Huploadify.js"></script>
<script type="text/javascript">
    $(function () {
        var keyId = (getUrlParam("keyId", url));
        fy_api.load_template({
            controller: $("#saveForm").attr("templateParam", "keyId=" + keyId), loading: true, initValue: true, loaded: function(){
                fileUploadInit();
                fileUploadLogoInit();
                if(keyId != ""){
                    //编辑
                    loadFileList();
                    loadFileLogoList();
                }else{
                    $.messager.alert('系统提示', "未找到对应数据信息", 'error', function () {
                        self.focus();
                    });
                }
                init();
            }
        });
    });

    function init(){
        var ue = UE.getEditor('notes',{
            toolbars:[['source', '|',
                'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'formatmatch', 'pasteplain', '|',
                'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','indent', '|',
                'horizontal', 'date', 'time', 'spechars', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',
                'preview', 'searchreplace']],
            autoHeightEnabled: true,
            autoFloatEnabled: true,
            initialFrameWidth: '95%',
            initialFrameHeight:483,
            elementPathEnabled : false,
            wordCount:false,
            autoHeightEnabled:false
        });

        var ue = UE.getEditor('consignAgreement',{
            toolbars:[['source', '|',
                'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'formatmatch', 'pasteplain', '|',
                'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify','indent', '|',
                'horizontal', 'date', 'time', 'spechars', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', '|',
                'preview', 'searchreplace']],
            autoHeightEnabled: true,
            autoFloatEnabled: true,
            initialFrameWidth: '95%',
            initialFrameHeight:483,
            elementPathEnabled : false,
            wordCount:false,
            autoHeightEnabled:false
        });

        $("#btnSave").click(function () {
            if (!checkForm(document.getElementById("saveForm"))) {
                return;
            }

            if(undefined == $("#attachmentLogo").find("li") || $("#attachmentLogo").find("li").length == 0){
                addError($("#fileUploadLogo"),"请上传图片.");
                return;
            }
            if(undefined == $("#attachment").find("li") || $("#attachment").find("li").length == 0){
                addError($("#fileUpload"),"请上传图片.");
                return;
            }

            var flag = false;
            $("input[chooseTime]").each(function(){
                var f = checkIsTime($(this));
                if(f == false){
                    addError($(this),"不能为空,且格式为24小时制(HH:mm:ss),如:15:00:00或09:30:00.");
                    flag = false;
                    return false;
                }else{
                    flag = true;
                }
            });
            if(flag == false){
                return;
            }

            $("#btnSave").blur();
            showLoading();
            <!-- 拼接 公章图片地址 imgurl  -->
            var imgurl = "";
            $("#attachment").find("li").each(function(){
                var tempurl = $(this).attr("id");
                imgurl += tempurl + ",";
            });
            if("" != imgurl && imgurl.length > 2){
                imgurl = imgurl.substr(0,imgurl.length - 1);
                $("#imgUrl").val(imgurl);
            }
            <!-- 拼接 公司Logo图片地址 imgurl  -->
            var logoImgUrl = "";
            $("#attachmentLogo").find("li").each(function(){
                var tempurl = $(this).attr("id");
                logoImgUrl += tempurl + ",";
            });
            if("" != logoImgUrl && logoImgUrl.length > 2){
                logoImgUrl = logoImgUrl.substr(0,logoImgUrl.length - 1);
                $("#logoImgUrl").val(logoImgUrl);
            }
            var fileInputs = $("#saveForm").find("input[type='file']").attr("type","hidden");
            fy_api.ajaxSubmit($("#saveForm"),{
                success: function (data) {
                    hideLoading();
                    if (!isSuccess(data)) {
                        $.messager.alert('系统提示', data.msg, 'error', function () {
                            self.focus();
                        });
                    } else {
                        parent.grid_get("grid").datagrid("load");
                        turnBack();
                    }
                }
            });
        });
    }

    function turnBack() {
        parent.j_closeWin();
    }

    function  chooseTime(){
        WdatePicker({dateFmt:'HH:mm:ss',quickSel:['#{%H-1}:00:00','#{%H-1}:30:00','%H:00:00','#{%H}:30:00','#{%H+1}:00:00'],isShowToday:false,isShowClear:true});
    }

    //验证是否为HH:mm:ss格式
    function checkIsTime(obj){
        if(undefined != obj && undefined != $(obj).val() && null != $(obj).val() && "" != $(obj).val()){
//            var reg=/^((20|21|22|23|[0-1]\d)\:[0-5][0-9])(\:[0-5][0-9])?$/;
            var reg=/^([0-9]|([0-1][0-9])|([2][0-3]))\:[0-5][0-9]\:[0-5][0-9]$/;
            if(reg.test($(obj).val())){
                return true;
            }
        }
        return false;
    }

    //上传构件
    function fileUploadInit(){
        //定义上传文件类型
        var fileUploadType = "uploadfile";
        //保存文件到服务器上的路径
        var fileSavePath = saveBasePathInServer + "company/images/";
        $('#fileUpload').Huploadify({
            auto:false,
            fileTypeExts:'*.jpg;*.png;*.jpge;*.bmp;*.gif',
            multi:false,
            formData:{savePath:fileSavePath},
            fileSizeLimit:10200,
            showUploadedPercent:false,
            showUploadedSize:false,
            removeTimeout:1000,
            uploader:uploadServer + fileUploadType + "&savePath=" + fileSavePath,
            method:'post',
            onUploadStart:function(file){},
            onInit:function(obj){},
            onUploadSuccess:function(file,data){
                data = eval("(" + data + ")");
                if(data.state == "SUCCESS"){
                    var fileName = file.name;
                    var fileUrl = lookingServer + data.url;
                    //如果是图片文件则显示图片，否则显示文件的连接
                    if(data.type == ".zip"){
                        $("#attachment").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                            "<a target='_blank' href='" + fileUrl + "'>" +
                            "<img src='../../../static/images/zipPic.png' height='30px' width='30px' style='margin-right:20px;' />" +
                            "<div>" + fileName + "</div>" +
                            "</a>" +
                            "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                            "</li>");
                    }else{
                        $("#attachment").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                            "<a target='_blank' href='" + fileUrl + "'>" +
                            "<img src='" + fileUrl + "?_t=" + Math.random() + "' height='30px' width='30px' style='margin-right:20px;' />" +
                            "<div>" + fileName + "</div>" +
                            "</a>" +
                            "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                            "</li>");
                    }
                    if($("#attachment").find("li").length > 1){
                        $("#attachment").children().first().remove();
                    }
                }else{
                    j_tip("[" + file.name + "]" + data.state,"error");
                }
            },
            onUploadComplete:function(file){},
            onCancel:function(file){},
            onClearQueue:function(queueItemCount){},
            onDestroy:function(){},
            onSelect:function(file){},
            onQueueComplete:function(queueData){}
        });
    }

    //上传构件
    function fileUploadLogoInit(){
        //定义上传文件类型
        var fileUploadType = "uploadfile";
        //保存文件到服务器上的路径
        var fileSavePath = saveBasePathInServer + "company/images/";
        $('#fileUploadLogo').Huploadify({
            auto:false,
            fileTypeExts:'*.jpg;*.png;*.jpge;*.bmp;*.gif',
            multi:false,
            formData:{savePath:fileSavePath},
            fileSizeLimit:10200,
            showUploadedPercent:false,
            showUploadedSize:false,
            removeTimeout:1000,
            uploader:uploadServer + fileUploadType + "&savePath=" + fileSavePath,
            method:'post',
            onUploadStart:function(file){},
            onInit:function(obj){},
            onUploadSuccess:function(file,data){
                data = eval("(" + data + ")");
                if(data.state == "SUCCESS"){
                    var fileName = file.name;
                    var fileUrl = lookingServer + data.url;
                    //如果是图片文件则显示图片，否则显示文件的连接
                    if(data.type == ".zip"){
                        $("#attachmentLogo").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                            "<a target='_blank' href='" + fileUrl + "'>" +
                            "<img src='../../../static/images/zipPic.png' height='30px' width='30px' style='margin-right:20px;' />" +
                            "<div>" + fileName + "</div>" +
                            "</a>" +
                            "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                            "</li>");
                    }else{
                        $("#attachmentLogo").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                            "<a target='_blank' href='" + fileUrl + "'>" +
                            "<img src='" + fileUrl + "?_t=" + Math.random() + "' height='30px' width='30px' style='margin-right:20px;' />" +
                            "<div>" + fileName + "</div>" +
                            "</a>" +
                            "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                            "</li>");
                    }
                    if($("#attachmentLogo").find("li").length > 1){
                        $("#attachmentLogo").children().first().remove();
                    }
                }else{
                    j_tip("[" + file.name + "]" + data.state,"error");
                }
            },
            onUploadComplete:function(file){},
            onCancel:function(file){},
            onClearQueue:function(queueItemCount){},
            onDestroy:function(){},
            onSelect:function(file){},
            onQueueComplete:function(queueData){}
        });
    }

    //图片鼠标移入事件
    function imgOver(obj){
        $(obj).children("span").show();
    }
    //图片鼠标移出事件
    function imgOut(obj){
        $(obj).children("span").hide();
    }

    //删除图片
    function imgDel(obj){
        if(confirm("确定删除此图片吗?", "提示")){
            $(obj).parent().remove();
        }
    }

    //加载附件
    function loadFileList(){
        var fileUrlsArr = new Array();
        var fileUrls = $("#imgUrl").val();
        if(fileUrls.length > 0){
            for(var i = 0; i < fileUrls.split(",").length; i++){
                var fileUrl =  fileUrls.split(",")[i];
                if("" != fileUrl && undefined != fileUrl){
                    var fileName = fileUrl.substr(fileUrl.lastIndexOf("/") + 1,fileUrl.length);
                }
                if(fileUrl.substr(fileUrl.length-4) == ".zip"){
                    $("#attachment").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                        "<a target='_blank' href='" + fileUrl + "'>" +
                        "<img src='../../../static/images/zipPic.png' height='30px' width='30px' style='margin-right:20px;' />" +
                        "<div>" + fileName + "</div>" +
                        "</a>" +
                        "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                        "</li>");
                }else{
                    $("#attachment").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                        "<a target='_blank' href='" + fileUrl + "'>" +
                        "<img src='" + fileUrl + "?_t=" + Math.random() + "' height='30px' width='30px' style='margin-right:20px;' />" +
                        "<div>" + fileName + "</div>" +
                        "</a>" +
                        "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                        "</li>");
                }
            }
        }
    }

    //加载附件
    function loadFileLogoList(){
        var fileUrlsArr = new Array();
        var fileUrls = $("#logoImgUrl").val();
        if(fileUrls.length > 0){
            for(var i = 0; i < fileUrls.split(",").length; i++){
                var fileUrl =  fileUrls.split(",")[i];
                if("" != fileUrl && undefined != fileUrl){
                    var fileName = fileUrl.substr(fileUrl.lastIndexOf("/") + 1,fileUrl.length);
                }
                if(fileUrl.substr(fileUrl.length-4) == ".zip"){
                    $("#attachmentLogo").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                        "<a target='_blank' href='" + fileUrl + "'>" +
                        "<img src='../../../static/images/zipPic.png' height='30px' width='30px' style='margin-right:20px;' />" +
                        "<div>" + fileName + "</div>" +
                        "</a>" +
                        "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                        "</li>");
                }else{
                    $("#attachmentLogo").append("<li id='" + fileUrl + "' title='" + fileName + "'>" +
                        "<a target='_blank' href='" + fileUrl + "'>" +
                        "<img src='" + fileUrl + "?_t=" + Math.random() + "' height='30px' width='30px' style='margin-right:20px;' />" +
                        "<div>" + fileName + "</div>" +
                        "</a>" +
                        "<span class='button-link icon-config-delete' title='删除文件' onclick='imgDel(this)'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span>" +
                        "</li>");
                }
            }
        }
    }
</script>
<form action="company/updateCompany.do" method="post" id="saveForm" templateUrl="company/get.do">
    <div id="divEdit">
        <input type="hidden" name="id" value="${content.id}"/>
    </div>
    <table style="margin: 10px auto;border: 1px solid darkgrey;padding: 10px">
        <tr>
            <td>
                <div class="div-label">企业名称：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.name}</span>
                </div>
            </td>
            <td>
                <div class="div-label">金融代码：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.code}</span>
                </div>
            </td>
            <td>
                <div class="div-label">联系方式：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.phone}</span>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">企业地址：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.address}</span>
                </div>
            </td>
            <td>
                <div class="div-label">创建时间：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.createTime}</span>
                </div>
            </td>
            <td>
                <div class="div-label"><span class="nullTip">*</span>url：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="url" isNull value="${content.url}" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">F6账套名称：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="f6AccountSet" value="${content.f6AccountSet}" />
                </div>
            </td>
            <td>
                <div class="div-label">F6组织代码：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="f6OrganizationCode" value="${content.f6OrganizationCode}" />
                </div>
            </td>
            <td>
                <div class="div-label">地区：</div>
            </td>
            <td>
                <div class="div-item">
                    <span class="div-item-info">${content.administrativeDivisionCode}</span>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label"><span class="nullTip">*</span>下单状态：</div>
            </td>
            <td>
                <div class="div-item">
                    <select name="makeOrderFlag" id="makeOrderFlag" style="width: 80px;" value="${content.makeOrderFlag}" >
                        <option value="1" >启用</option>
                        <option value="0" >禁用</option>
                    </select>
                </div>
            </td>
            <td>
                <div class="div-label"><span class="nullTip">*</span>取款状态：</div>
            </td>
            <td>
                <div class="div-item">
                    <select name="withdrawFlag" id="withdrawFlag" style="width: 80px;" value="${content.withdrawFlag}" >
                        <option value="1" >启用</option>
                        <option value="0" >禁用</option>
                    </select>
                </div>
            </td>
            <td>
                <div class="div-label"><span class="nullTip">*</span>推送状态：</div>
            </td>
            <td>
                <div class="div-item">
                    <select name="sendMsgFlag" id="sendMsgFlag" style="width: 80px;" value="${content.sendMsgFlag}" >
                        <option value="1" >启用</option>
                        <option value="0" >禁用</option>
                    </select>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label"><span class="nullTip">*</span>首页图片显示数量：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" name="imgLimit" isNull isInt numType="1" value="${content.imgLimit}" />
                </div>
            </td>
            <td>
                <div class="div-label">开始营业时间：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" chooseTime readonly onclick="chooseTime()" id="businessStartTime" name="businessStartTime" value="${content.businessStartTime}"  />
                </div>
            </td>
            <td>
                <div class="div-label">结束营业时间：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" chooseTime readonly onclick="chooseTime()" name="businessEndTime" value="${content.businessEndTime}" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">开始放款时间：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" chooseTime readonly onclick="chooseTime()" name="lendingStartTime" value="${content.lendingStartTime}" />
                </div>
            </td>
            <td>
                <div class="div-label">结束放款时间：</div>
            </td>
            <td>
                <div class="div-item">
                    <input type="text" chooseTime readonly onclick="chooseTime()" name="lendingEndTime" value="${content.lendingEndTime}" />
                </div>
            </td>
            <td>
                <div class="div-label"><span class="nullTip">*</span>是否定制：</div>
            </td>
            <td>
                <div class="div-item">
                    <select name="isCustom" id="isCustom" style="width: 80px;" value="${content.isCustom}" >
                        <option value="1" >是</option>
                        <option value="0" >否</option>
                    </select>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">主营线路：</div>
            </td>
            <td colspan="5">
                <div class="div-item" style="width: 90%;height: 95%">
                    <!--<span class="div-item-info">${content.line}</span>-->
                    <input type="text" name="line" value="${content.line}" />
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label"><span class="nullTip">*</span>Logo图片：</div>
            </td>
            <td>
                <input type="hidden" id="logoImgUrl" name="logoImgUrl" value="${content.logoImgUrl}"/>
                <div id="fileUploadLogo"></div>
            </td>
            <td colspan="4">
                <ul id="attachmentLogo" style="padding:5px"></ul>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label"><span class="nullTip">*</span>图片：</div>
            </td>
            <td>
                <input type="hidden" id="imgUrl" name="imgUrl" value="${content.imgUrl}"/>
                <div id="fileUpload"></div>
            </td>
            <td colspan="4">
                <ul id="attachment" style="padding:5px"></ul>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">托运协议：</div>
            </td>
            <td colspan="5">
                <div class="div-item" style="width: 90%;height: 95%">
                    <textarea readonly="readonly" name="consignAgreement" id="consignAgreement">${content.consignAgreement}</textarea>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div class="div-label">发货须知：</div>
            </td>
            <td colspan="5">
                <div class="div-item" style="width: 90%;height: 95%">
                    <textarea readonly="readonly" name="notes" id="notes">${content.notes}</textarea>
                </div>
            </td>
        </tr>
    </table>
</form>
<div class="form-buttons">
    <a id="btnSave" class="easyui-linkbutton" iconCls="icon-save">保存</a>
    <a id="btnBack" class="easyui-linkbutton c2" iconCls="icon-undo" onClick="turnBack();">返回</a>
</div>